﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Fcdbas.Core;

namespace Fcdbas.Biz
{
    public class FndSession
    {
        private string link_name = "";
        public string LINK_NAME
        {
            set { link_name = value; }
            get { return link_name; }
        }

        private string type = "";
        public string TYPE
        {
            set { type = value; }
            get { return type; }
        }

        private string user_id = "";
        [XmlIgnoreAttribute]
        public string USER_ID
        {
            set { user_id = value; }
            get { return user_id; }
        }

        private string user_pwd = "";
        [XmlIgnoreAttribute]
        public string USER_PWD
        {
            set { user_pwd = value; }
            get { return user_pwd; }
        }

        private string connection = "";
        public string CONNECTION
        {
            set { connection = value; }
            get { return connection; }
        }
        public string Server
        {
            get;
            set;
        }
        public string Database
        {
            get;
            set;
        }
        public int Port
        {
            get;
            set;
        }
        private string description = "";
        public string DESCRIPTION
        {
            set { description = value; }
            get { return description; }
        }
        [XmlIgnoreAttribute]
        public bool IsLast
        {
            get;
            set;
        }
         [XmlIgnoreAttribute]
        public bool IsRoot
        {
            get;
            set;
        }
        public string Language
        {
            get;
            set;
        }
        public string OS_User
        {
            get;
            set;
        }
        public string Fnd_Version
        {
            get;
            set;
        }
        public string Program
        {
            get;
            set;
        }
        public string Machine
        {
            get;
            set;
        }
        public string IP
        {
            get;
            set;
        }
        public string OS_Version
        {
            get;
            set;
        }
        public string StartupPath
        {
            get;
            set;
        }
        public static string GetSessionID()
        {
            SalString sSql = "SELECT CONNECTION_ID()";
            return Fcdbas.WinUI.Common .cSessionManager.GetUserFunctionValue<string>(sSql, false);
        }
        public string GetAttr()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("FND_USER");
            
            sb.Append(EntityBase.Field_Separator);
            sb.Append(this.USER_ID);
            
            sb.Append(EntityBase.Record_Separator);
            sb.Append("SESSION_ID");
            sb.Append(EntityBase.Field_Separator);
            sb.Append(GetSessionID());

            sb.Append(EntityBase.Record_Separator);

            sb.Append("LANGUAGE");
            sb.Append(EntityBase.Field_Separator);
            sb.Append(this.Language);
            sb.Append(EntityBase.Record_Separator);

            sb.Append("OS_USER");
            sb.Append(EntityBase.Field_Separator);
            sb.Append(this.OS_User);
            sb.Append(EntityBase.Record_Separator);

            sb.Append("FND_VERSION");
            sb.Append(EntityBase.Field_Separator);
            sb.Append(this.Fnd_Version);
            sb.Append(EntityBase.Record_Separator);

            sb.Append("DB_PORT");
            sb.Append(EntityBase.Field_Separator);
            sb.Append(this.CONNECTION);
            sb.Append(EntityBase.Record_Separator);

            sb.Append("PROGRAM");
            sb.Append(EntityBase.Field_Separator);
            sb.Append(this.Program);
            sb.Append(EntityBase.Record_Separator);

            sb.Append("MACHINE");
            sb.Append(EntityBase.Field_Separator);
            sb.Append(this.Machine);
            sb.Append(EntityBase.Record_Separator);

            return sb.ToString();
        }
    }
    public class LogonUser
    {
        public bool IsLast
        {
            get;
            set;
        }
        private string user_id = "";
        public string USER_ID
        {
            set { user_id = value; }
            get { return user_id; }
        }

        private string user_pwd = "";
        public string USER_PWD
        {
            set { user_pwd = value; }
            get { return user_pwd; }
        }
        private string link_name = "";
        public string LINK_NAME
        {
            set { link_name = value; }
            get { return link_name; }
        }
        public DateTime LastLogonDate
        {
            get;
            set;
        }
        public bool IsRoot
        {
            get;
            set;
        }
    }
}
